<template>
  <div>
    <el-dialog title="属性同步" :visible="dialogVisible" :close-on-click-modal="false" @close="close" width="500px">
      <div v-loading="loading">
        <el-form :model="ruleForm" ref="ruleForm" :inline="true" label-width="80px" :rules="rules" class="demo-ruleForm">
          <el-form-item label="渠道:" prop="code">
            <el-select
              filterable
              clearable
              v-model="ruleForm.code"
              placeholder="请选择"
            >
              <el-option
                v-for="item in listAttr"
                :key="item.id"
                :label="item.name"
                :value="item.code"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="游戏:" prop="gameId">
            <el-select
              filterable
              clearable
              v-model="ruleForm.gameId"
              placeholder="请选择"
            >
              <el-option
                v-for="item in allGameList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
        
        </el-form>
        <div class="center">
          <el-button @click="close('ruleForm')">取消</el-button>
          <el-button type="primary"  @click="submitForm('ruleForm')" :loading="loading">确认</el-button>
        </div>
      </div>
      
    </el-dialog>
  </div>
</template>

<script>
import interfaceChannelApi from "../../api/shanghuduan/interfaceChannel";
export default {
  name: "",
  data() {
    return {
      dialogVisible: false,
      loading: false,
      listAttr: [],
      ruleForm: {
        code: "",
        gameId: ""
      },
      rules: {
        code: [
            { required: true, message: '请选择渠道', trigger: 'change' }
          ],
          gameId: [
            { required: true, message: '请选择游戏', trigger: 'change' }
          ],
      },

    };
  },
  computed: {
    allGameList() {
      return this.$store.getters.allGameList;
    },
  },
  created() {
    
  },
  methods: {
    open(billInfo) {
      this.loading = false;
    
      this.dialogVisible = true;
      this.getQudaoList()
    },
    async getQudaoList() {
      this.loading = true
      try {
        const res = await interfaceChannelApi.getAllList({isPage:2});
        this.listAttr = res.rows;
      } catch (error) {
        
      }
      this.loading = false
    },
    // 核验
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.loading = true
          interfaceChannelApi.shangxiajiatongji(this.ruleForm).then(res=>{
            this.loading = false
            this.$message.success('后台处理中！同一游戏，同一渠道，3-5分钟内不要重复提交！')
            this.close()
          }).catch(err=>{
            this.loading = false
          })
         
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
 
    close() {
      this.resetForm('ruleForm')
      this.dialogVisible = false;
    },
  },
};
</script>
<style scoped lang="scss">

</style>
